package com.sugon.controller.analyse;

import cn.hutool.core.util.StrUtil;
import com.sugon.entity.DevLineDevCoordinateEntity;
import com.sugon.service.DevLineDevCoordinateService;
import com.sugon.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description: 设备二维平面图Controller
 * @author: YuXD
 * @create: 2020-05-10 17:08
 **/
@RestController
@RequestMapping("devPlane")
public class Dev2DPlaneController {

    @Autowired
    private DevLineDevCoordinateService lineDevCoordService;

    /**
     * 校验当前产线二维平面图配置是否存在
     */
    @GetMapping("/check")
    public R topFault(@RequestParam("lineCode") String lineCode) {
        DevLineDevCoordinateEntity coordData = lineDevCoordService.getByCode(lineCode);
        return coordData != null && StrUtil.isNotEmpty(coordData.getUrl()) ? R.ok() : R.error("当前产线未配置平面图");
    }

    /**
     * 根据产线CODE获取产线下设备坐标配置信息
     */
    @GetMapping("/devCoorSetting")
    public R getLineDevCoorSetting(@RequestParam("lineCode") String lineCode) {
        return R.ok().put("lineDevCoorSetting", lineDevCoordService.getLineDevCoorSetting(lineCode));
    }


    /**
     * 根据产线CODE获取产线下配置信息
     */
    @GetMapping("/lineData")
    public R getLineData(@RequestParam("lineCode") String lineCode) {
        DevLineDevCoordinateEntity line = lineDevCoordService.getByCode(lineCode);
        return line != null && StrUtil.isNotEmpty(line.getUrl()) ? R.ok().put("lineData", line) : R.error("产线[" + lineCode + "]尚未配置平面图");
    }

}
